package com.bingxue.edu.management.education.service.exam;

import com.bingxue.edu.framework.mybatis.base.BaseService;
import com.bingxue.edu.management.education.mapper.exam.ExamQuestionMapper;
import com.bingxue.edu.management.education.model.entity.exam.ExamQuestion;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.bingxue.edu.management.education.model.entity.exam.table.ExamQuestionTableDef.EXAM_QUESTION;

@Slf4j
@Service
@RequiredArgsConstructor
public class ExamQuestionService extends BaseService<ExamQuestionMapper, ExamQuestion> {
    @Transactional(rollbackFor = Exception.class)
    public void remove(List<String> ids) {
        this.removeByIds(ids);
    }


    @Transactional(rollbackFor = Exception.class)
    public void saveList(List<ExamQuestion> questionList) {
        this.saveBatch(questionList);
    }

    public void removeByExamId(String examId) {
        QueryWrapper removeExamQuestionQueryWrapper = QueryWrapper.create()
                .where(EXAM_QUESTION.EXAM_ID.eq(examId));
        this.remove(removeExamQuestionQueryWrapper);
    }

    public List<ExamQuestion> getListByExamId(String examId) {
        QueryWrapper examQuestionQueryWrapper = QueryWrapper.create()
                .select(EXAM_QUESTION.ALL_COLUMNS)
                .where(EXAM_QUESTION.EXAM_ID.eq(examId));
        return this.list(examQuestionQueryWrapper);
    }
}
